from rest_framework import serializers

from .models import *


class AnswerTableSerializers(serializers.ModelSerializer):
    class Meta:
        model = Answertable
        fields = ('SubjectTitle_Id', 'Item', 'ItemContent', 'ItemCA')


# 对题目及对应选项序列化
class SubjectTitleSerializers(serializers.ModelSerializer):
    subject_answer = AnswerTableSerializers(many=True)

    class Meta:
        model = SubjectTitle
        fields = ('QuestionType_id', 'Title', 'subject_answer')


class QuestionTypeListSerializers(serializers.ModelSerializer):
    question_subbject = SubjectTitleSerializers(many=True)

    class Meta:
        model = QuestionType
        fields = ('typename', 'num', 'needtime', 'isfree', 'price', 'question_subbject')


class QuestionListSerializers(serializers.ModelSerializer):
    class Meta:
        model = QuestionType
        fields = ('questiontype_id', 'typename', 'introduce', 'num', 'needtime', 'isfree', 'price')
